/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client;

import client.net.Client;
import client.pipeConnector.IPipe;
import client.pipeConnector.PipeConnectorBuffered;
import client.pipeConnector.PipeConnectorRW;
import client.pipeConnector.PipeConnectorStreamed;
import client.ui.ClientUI;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.channels.Pipe;
import java.nio.channels.Pipe.SinkChannel;
import java.nio.channels.Pipe.SourceChannel;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author Александр Емельянов (mr.lex91@gmail.com)
 */
public class ClientStart {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
//          try {
//              for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                  if ("Nimbus".equals(info.getName())) {
//                      javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                      break;
//                  }
//              }
//          } catch (ClassNotFoundException ex) {
//              java.util.logging.Logger.getLogger(ClientUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          } catch (InstantiationException ex) {
//              java.util.logging.Logger.getLogger(ClientUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          } catch (IllegalAccessException ex) {
//              java.util.logging.Logger.getLogger(ClientUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//              java.util.logging.Logger.getLogger(ClientUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//          }
        try {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ClientStart.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(ClientStart.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(ClientStart.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(ClientStart.class.getName()).log(Level.SEVERE, null, ex);
        }
        String host="localhost";
        int port=8000;
        try {
            // TODO code application logic here
            FileInputStream fis=new FileInputStream("client.ini");
            Scanner scan=new Scanner(fis);
            while (scan.hasNext())
            {
                String header=scan.next();
                header=header.substring(0, header.length()-1);
                String body=scan.nextLine();
                body=body.substring(1,body.length());
                if (header.equalsIgnoreCase("host")) host=body;
                else if (header.equalsIgnoreCase("port")) port=Integer.valueOf(body);
            }
            fis.close();
        } catch (IOException ex) {}
        try
        {
            IPipe[] pc=PipeConnectorBuffered.createPipe();
//            IPipe[] pc=PipeConnectorRW.createPipe();
//            IPipe[] pc=PipeConnectorStreamed.createPipe();
            new ClientUI(pc[0]).Show();
            new Client(pc[1], host, port).Start();
        }
        catch (IOException ex) {}
    }
}
